<template>
	<view class="personal">
		<gyd-navbar back-color="#fff" :title="title"></gyd-navbar>

		<up-cell-group>
			<up-cell title="头像" :isLink="true" @click="chooseAvatar">
				<template #value>
					<u-avatar :src="member.avatar" size="50"></u-avatar>
				</template>
			</up-cell>
			<up-cell title="昵称" :value="member.nickname" :isLink="true"
				:url="'/userPages/setting/nickname?nickname=' + member.nickname"></up-cell>
			<up-cell title="手机号码" :value="member.mobile" :isLink="true"
				:url="'/userPages/setting/change-phone?mobile=' + member.mobile"></up-cell>
			<up-cell title="注册日期" :value="member.create_time"></up-cell>
		</up-cell-group>
	</view>
</template>

<script setup>
	import request from '@/utils/request';
	import cache from '@/utils/cache';
	import util from '@/utils/util';
	import {
		reactive,
		toRefs,
		inject,
		ref,
	} from 'vue';
	import {
		onLoad,
		onShow,
		onReady,
		onPullDownRefresh,
		onReachBottom,
	} from '@dcloudio/uni-app';

	const state = reactive({
		title: '个人中心',
		themeColor: cache.get('themeColor'),
		imgHost: util.requestUrl(),
		member: false,
	});

	//在页面所有元素加载完成后执行（只执行一次）
	onLoad((opt) => {
		console.log('onLoad');
		if (opt.hasOwnProperty('id')) {
			console.log('传递参数', opt.id);
		}
		initData();
	});

	//在页面由不可见变为可见时执行（只要页面显示都会执行）
	onShow(() => {
		console.log('onShow');
	})

	//在页面解析完成之后执行
	onReady(() => {
		console.log('onReady');
	})

	onPullDownRefresh(() => {
		console.log('下拉刷新');
		setTimeout(() => {
			uni.stopPullDownRefresh();
		}, 1000);
	})

	onReachBottom(() => {
		console.log('触底加载更多');
	})

	function initData() {
		state.member = {
			id: 10001,
			avatar: state.imgHost + '/static/images/avatar.png',
			nickname: '王云海',
			mobile: '15825258992',
			tags: '',
			agent_level: 1,
			agent_level_name: '省级代理',

			money: '100.00',
			income: '115.00',
			commission: '2100.35',
			coupon: 2,
			points: '130.00',
			water_tickets: 10,
			opening_award: '16.50',
			create_time: '2025-08-18 13:26:16'
		}
	}

	function chooseAvatar() {
		console.log('选择头像');
	}

	function pageRoute(url) {
		uni.navigateTo({
			url
		});
	}

	function pageTabRoute(url) {
		uni.reLaunch({
			url
		});
	}

	const {
		title,
		themeColor,
		imgHost,
		member,
	} = toRefs(state);
</script>

<style lang="scss">

</style>